import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: () => import('../views/home.vue'),
    children: [{ //页面右侧的内容显示
      path: '/users',
      name: 'users',
      component: () => import('../views/users.vue'),
    }]
  },
  //登录系统
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  //网页详情
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue'),
    children: [{ //页面右侧的内容显示
      path: '/users',
      name: 'users',
      component: () => import('../views/users.vue'),
    }]
  }
]



const router = new VueRouter({
  routes
})
//导航守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/home' || to.path == '/') {
    if (!localStorage.getItem('userinfo')) {
      next('/login')
    }
  }
  next()
})
export default router